import { computed } from 'vue'
/**
 * 查看工具栏与标注工具栏互通函数
 * @param currentIndex 当前工具栏选中id
 * @param list 
 */
export const changeToolBarIndex = (list?: Header.QueryDataList[] | Header.MarkDataList[]) => {
  list && list.map(item => item.isVisible = false);
}
//集合状态互斥
export const makeListMer = (list: any[], it: Header.QueryDataList | Header.MarkDataList) => {
  list && list.map((item: any) => {
    const active = (item.code === it.code)
    item.isActive = active
    item.isVisible = active
  });
}

export const useVModel = (props: { [x: string]: any; }, propName: string | number, emit: (arg0: string, arg1: any) => void) => {
  return computed({
    get(){
      return new Proxy(props[propName], {
        set(obj, name, val) {
          emit(`update:${propName}`, {
            ...obj,
            [name]: val
          });
          return true;
        }
      })
    },
    set(val){
      emit(`update:${propName}`, val);
    }
  })
}